<?php
class Admin_Model_Article extends Zend_Db_Table_Abstract{
    protected $_name = 'articles';
    protected $_primary = 'id';

    public function getArticleInfo(){
      $select = $this->select()
                      ->where('status = ?', 1);
      return $this->fetchAll($select);      
    }

    public function getArticleOne($id){
        $select = $this->select()
                      ->where('id = ?', $id, INTEGER)
                      ->where('status = ?', 1);
        return $this->fetchRow($select);
    }

    public function addArticle($info){      
      $id = $this->insert( $info );
      
      return $id;
    }

    public function updateArticle($id,$info){        
      $this->update( $info, "id=" . (int) $id );
    }
    
    public function deleteArticle($id){
      $this->delete("id = ". (int) $id);
    }
    
    public function countItems(){
      $query = $this->select()
              ->from($this->_name,'count(id) as total');
      $result = $this->fetchRow($query);
      return $result->total;
    }
}